package me.exchange.com.modules.system.domain;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.CreationTimestamp;

import javax.persistence.*;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.sql.Timestamp;
import java.util.Objects;
import java.util.Set;





/**
 * 角色
 * @author Zheng Jie
 * @date 2018-11-22
 */
@Entity
@Getter
@Setter
@Table(name = "sys_role")
@org.hibernate.annotations.Table(appliesTo = "sys_role",comment="角色表")
public class Role implements Serializable {
    /** serialVersionUID*/
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @NotNull(groups = {Update.class})
    @ApiModelProperty(name = "id",value = "ID",required = false)
    private Long id;

    /** 角色名称*/
    @NotBlank
    @Column(name = "role_name")
    @ApiModelProperty(name = "roleName",value = "角色名称",required = false)
    private String roleName;

    /** 角色级别*/
    @Column(name = "level")
    @ApiModelProperty(name = "level",value = "角色级别",required = false)
    private Integer level = 3;

    /** 数据权限*/
    @NotBlank
    @Column(name = "data_scope")
    @ApiModelProperty(name = "dataScope",value = "数据权限",required = false)
    private String dataScope = "本级";

    /** 创建人*/
    @Column(name = "c_admin_id")
    @ApiModelProperty(name = "cAdminId",value = "创建人",required = false)
    private Long cAdminId;

    /** 创建时间*/
    @Column(name = "c_admin_time")
    @CreationTimestamp
    @ApiModelProperty(name = "cAdminTime",value = "创建时间",required = false)
    private Timestamp cAdminTime;

    /** 修改人*/
    @Column(name = "u_admin_id")
    @ApiModelProperty(name = "uAdminId",value = "修改人",required = false)
    private Long uAdminId;

    /** 修改时间  */
    @Column(name = "u_admin_time")
    @CreationTimestamp
    @ApiModelProperty(name = "uAdminTime",value = "修改时间",required = false)
    private Timestamp uAdminTime;

    /** 备注*/
    @Column(name = "remark")
    @ApiModelProperty(name = "remark",value = "备注",required = false)
    private String remark;

    /** 是否删除*/
    @Column(name = "isdel")
    @ApiModelProperty(name = "isdel",value = "是否删除",required = false)
    private Boolean isdel;

    @ManyToMany
    @JoinTable(name = "sys_roles_menus", joinColumns = {@JoinColumn(name = "role_id",referencedColumnName = "id")}, inverseJoinColumns = {@JoinColumn(name = "menu_id",referencedColumnName = "id")})
    private Set<Menu> menus;

    public @interface Update {}

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        Role role = (Role) o;
        return Objects.equals(id, role.id);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id);
    }
}
